$(function () {
    $('#captcha-img').click(function (event) {
       var self = $(this);
       var src = self.attr('src');
        var newsrc = zlparam.setParam(src,'xx',Math.random());
        self.attr('src',newsrc);
    });
});

$(function () {
   $('#captcha-btn').click(function (event) {

   }) ;
});

$(function () {
   $('#submit').click(function (event) {
      event.preventDefault();

      var emailE = $('input[name="email"]');
      var captchaE = $('input[name="captcha"]');
      var usernameE = $('input[name="username"]');
      var password1E = $('input[name="password1"]');
      var password2E = $('input[name="password2"]');
      var graph_captchaE = $('input[name="graph_captcha"]');

       var email = emailE.val();
       var captcha = captchaE.val();
       var username = usernameE.val();
       var password1 = password1E.val();
       var password2 = password2E.val();
       var graph_captcha = graph_captchaE.val();

       zlajax.post({
           'url' : '/signup/',
           'data' : {
               'email' : email,
               'captcha' : captcha,
               'username' : username,
               'password1' : password1,
               'password2' : password2,
               'graph_captcha' : graph_captcha
           },
           'success' : function (data) {
               if (data['code'] == 200){
                   var return_to = $('#return-to-span').text();
                   if (return_to){
                       window.location = return_to;
                   }else {
                       window.location = '/';
                   }
               }else {
                   password1E.val('');
                   password2E.val('');
                   graph_captchaE.val('');
                   xtalert.alertInfo(data['message']);
               }
           },
           'fail' : function (error) {
               xtalert.alertNetworkError('网络错误！');
           }
       })


   });
});